from __future__ import annotations

from dataclasses import dataclass
from math import sqrt


@dataclass
class JumperResult:
    length_m: float
    min_clearance_m: float
    note: str


def estimate_jumper_length(horizontal_offset_m: float, vertical_drop_m: float, slack_ratio: float = 0.05) -> JumperResult:
    """跳线长度简化估算：按两点间距加松弛率。

    L ≈ √(Δx²+Δy²) × (1+slack)
    最小间隙随弧垂/布局变化，简化给出与松弛成比例的安全间隙。
    """

    chord = sqrt(horizontal_offset_m ** 2 + vertical_drop_m ** 2)
    L = chord * (1.0 + slack_ratio)
    clearance = 0.2 + 2.0 * slack_ratio
    return JumperResult(length_m=L, min_clearance_m=clearance, note="几何近似，需三维布置复核")


